Skip to content

Guard ProjectionExec::try_pushdown_sort against stale name/index metadata#156

Open
Jeadie wants to merge 5 commits into
spiceai-52.5from
jeadie/topk-projection-fetch-fix
Open

Guard ProjectionExec::try_pushdown_sort against stale name/index metadata#156
Jeadie wants to merge 5 commits into
spiceai-52.5from
jeadie/topk-projection-fetch-fix

Conversation

@Jeadie
Copy link
Copy Markdown

@Jeadie Jeadie commented Apr 21, 2026

Adds a safety check in ProjectionExec::try_pushdown_sort to prevent incorrect sort pushdown when a sort column’s (name, index) metadata is stale or mismatched. ProjectionExec translated parent sort requirements to child columns using index-only mapping:

  • take sort column col@i
  • map through projection.expr()[i]

If optimizer rewrites left a stale pair (e.g. name _score, index 3, but projection slot 3 is actually picked_at), pushdown could incorrectly rewrite _score@3 into picked_at@3, causing invalid ordering assumptions and potential SanityCheckPlan failures.

Copilot AI review requested due to automatic review settings April 21, 2026 01:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens sort pushdown through ProjectionExec by preventing rewrite/pushdown when a Column’s name doesn’t match the projection output alias at the same index (avoiding incorrect pushdown when column metadata is stale or mismatched).

Changes:

  • Add a name-vs-alias guard in ProjectionExec::try_pushdown_sort to reject pushdown when Column(name, index) doesn’t match the projection’s output alias at index.
  • Add a regression test ensuring sort pushdown does not occur when the sort column’s name/index metadata is inconsistent with the projection output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
datafusion/physical-plan/src/projection.rs Adds a safety check to avoid rewriting sort expressions through projections when column metadata is mismatched.
datafusion/core/tests/physical_optimizer/pushdown_sort.rs Adds a regression test snapshot covering the name/index mismatch scenario to ensure no pushdown occurs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jeadie Jeadie changed the title Jeadie/topk projection fetch fix Guard ProjectionExec::try_pushdown_sort against stale name/index metadata Apr 21, 2026
@Jeadie Jeadie self-assigned this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants